var c = require('checkAuthority');
var s = require('selectTransformat');

//获取url中的参数
function postQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}
var id = postQueryString("id");
var customsDeclaration = postQueryString("customsDeclaration");

//显示要用提单号customsDeclaration，编辑要用id
$.ajax({
	type: "post",
	url: "./order/searchorder.bto?customsDeclaration=" + customsDeclaration,
	success: function(data) {
		s.selectTransformat();
		s.transformatStatus();
		var authorityCode = data.code;

		function template() {
			var editDeclareTemplate = __inline('editDeclare.handlebars');
			$('#editDeclareForm').html(editDeclareTemplate(data.other.tbo.value.value[0]));
		}
		c.authority(authorityCode, template);
	}
});

yuki.check('trailerCost');
yuki.check('otherCost');
yuki.check('customsDeclarationCost');
yuki.check('trailerPayCost');
yuki.check('customsDeclarationPayCost');

/*修改报关信息*/
$('button[type=submit]').on('click', function() {
	$.ajax({
		type: "post",
		url: "./order/editorder.bto?id=" + id,
		data: $('#editDeclareForm').serialize(),
		success: function(data) {
			alert('修改成功');
			window.location.href = "declareManage.html"
		}
	});
});